package com.company.mvvm;

import android.content.Intent;
import android.util.Log;
import android.view.View;

import androidx.lifecycle.Observer;

import com.company.mvvm.base.BaseAct;
import com.company.mvvm.beans.ArticleBean;
import com.company.mvvm.databinding.ActivityMainBinding;
import com.company.mvvm.viewmodel.ArticleViewModel;
import com.company.network.enviroment.EnvironmentActivity;

public class MainActivity extends BaseAct<ActivityMainBinding, ArticleViewModel> {

    private final static String TAG = "MainActivity";

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        //获取文章数据
        viewModel.articleData.observe(this, new Observer<ArticleBean>() {
            @Override
            public void onChanged(ArticleBean articleBean) {
//                Log.e("TAG", articleBean.toString());
                binding.textView.setText(articleBean.getDatas().get(0).toString());
            }
        });
    }

    @Override
    protected ActivityMainBinding getViewBinding() {
        return ActivityMainBinding.inflate(getLayoutInflater());
    }

    @Override
    protected Class<ArticleViewModel> getModel() {
        return ArticleViewModel.class;
    }

    public void requestNet(View view) {
        viewModel.getArticle();
    }

    public void switchEnvClick(View view) {
        startActivity(new Intent(this, EnvironmentActivity.class));
    }
}